package com.springboot.last_experiment.controller;

import com.springboot.last_experiment.entity.Admin;
import com.springboot.last_experiment.service.AdminService;
import com.springboot.last_experiment.vo.ResultVO;
import com.springboot.last_experiment.voutils.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminController {
    @Autowired
    AdminService adminService;

    @PostMapping("/admin/login")
    public ResultVO login(@RequestParam("name") String name,
                          @RequestParam("password") String password){
        return adminService.admin_login(name,password);
    }
    /**
     *查询所有
     * @return
     */
    @GetMapping("/admins")
    public ResultVO getAllAdm(){
        return adminService.getAllAdm();
    }
    /**
     * 通过id查询某个
     * @param id
     * @return
     */
    @GetMapping("/admin/{id}")
    public ResultVO updatePage(@PathVariable("id") Integer id){
        Admin admin= adminService.getAdmById(id);
        return ResultVOUtil.success(admin);
    }
    /**
     * 搜索：姓名的模糊查询，根据性别搜索,根据ID搜索
     * @param key
     * @return
     */
    @GetMapping("/admins/{k}")
    public ResultVO getAdmByKey(@PathVariable("k") String key){
        return adminService.getAdmByKey(key);
    }

    /**
     * 添加管理员
     * @param admin
     * @return
     */
    @PostMapping("/admin")
    public ResultVO addEmp(Admin admin){
        return adminService.insertAdm(admin);
    }


    /**
     * 修改管理员信息
     * @param admin
     * @return
     */
    @PutMapping("/admin")
    public ResultVO update(Admin admin){
        return adminService.updateAdm(admin);
    }

    /**
     * 删除管理员
     * @param id
     * @return
     */
    @DeleteMapping("/admin/{id}")
    public ResultVO delete(@PathVariable("id") Integer id){
        return adminService.deleteAdm(id);
    }


}
